<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="shortcut icon" href="<!--{eval echo register_static('img/touch-icon-57x57.png');}-->">

    <title>粉粉管理系统</title>

    <!-- Bootstrap core CSS -->
    <link href="<!--{eval echo register_static('css/bootstrap.min.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/bootstrap-reset.css');}-->" rel="stylesheet">

    <!--Animation css-->
    <link href="<!--{eval echo register_static('css/animate.css');}-->" rel="stylesheet">

    <!--Icon-fonts css-->
    <link href="<!--{eval echo register_static('assets/font-awesome/css/font-awesome.css');}-->" rel="stylesheet" />
    <link href="<!--{eval echo register_static('assets/ionicon/css/ionicons.min.css');}-->" rel="stylesheet" />

    <link href="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.css');}-->" rel="stylesheet">

    <!-- Plugins css -->
    <link href="<!--{eval echo register_static('assets/modal-effect/css/component.css');}-->" rel="stylesheet">

    <!-- DataTables -->
    <link rel="stylesheet" href="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.css" rel="stylesheet');}-->" />

    <!-- Custom styles for this template -->
    <link href="<!--{eval echo register_static('css/style.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/helper.css');}-->" rel="stylesheet">

    <!-- My styles for this template -->
    <link href="<!--{eval echo register_static('css/common.css');}-->" rel="stylesheet">

</head>

<body>

<!-- Aside Start-->
<!--{template admin_v2/leftside}-->
<!-- Aside Ends-->


<!--Main Content Start -->
<section class="content">

    <!-- Header -->
    <!--{template admin_v2/header}-->
    <!-- Header Ends -->


    <!-- Page Content Start -->
    <!-- ================== -->

    <div class="wraper container-fluid diary-topics">

        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">匿名评论列表</h3>
                    </div>
                    <div class="panel-body">

                        <!--{if $list['anonymousInfo']}-->
                        <div class="col-md-12 col-sm-12 col-xs-12" style="margin-bottom: 10px">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th width="5%">bodyId</th>
                                    <th>标题</th>
                                    <th width="10%">内容</th>
                                    <th>背景</th>
                                    <th>uid</th>
                                    <th>创建于</th>
                                </tr>
                                </thead>

                                <tbody id="tbody">
                                    <tr>
                                        <td><label class="label label-success">{$list['anonymousInfo']['bodyId']}</label></td>
                                        <td><span style="color: #7E3D76">{$list['anonymousInfo']['title']}</span></td>
                                        <td><span style="color: #FF5809">{$list['anonymousInfo']['content']}</span></td>
                                        <td><img src="{$list['anonymousInfo']['bg_value']}" width="100" class="showImg" /></td>
                                        <td>{$list['anonymousInfo']['uid']}</td>
                                        <td><label class="label label-info">{$list['anonymousInfo']['create_at']}</label></td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <!--{/if}-->
                        <div class="row" style="margin-bottom: 10px">
                            <div class="col-md-9 col-sm-9 col-xs-9">
                                <!--search-->
                                <div class="extrabottom" style="margin-bottom:5px">
                                    <form class="form-inline" role="form" action="admin.php" method="get">
                                        <div class="form-group m-l-10">
                                            <label>输入bodyId:</label>
                                            <input class="span2 form-control" id="bodyid" type="text" placeholder="bodyid必填" name="cid" value="{$list['anonymousInfo']['bodyId']}">
                                            <input class="span2 form-control" id="pos" type="text" placeholder="输入楼层" name="pos" value="">
                                        </div>
                                        <input type="hidden" value="commentary" name="ac"/>
                                        <input type="hidden" value="searchCommentary" name="op"/>
                                        <input type="submit" value="搜索" class="btn btn-success m-l-10" id="search"/>
                                    </form>
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-3 col-xs-3">
                                <button class="btn btn-info myAdd"><i class="ion-plus-round"></i> 添加评论</button>
                            </div>
                        </div>
                            <div class="col-md-12 col-sm-12 col-xs-12">
                                <table id="datatable" class="table table-striped table-bordered">
                                    <thead>
                                    <tr>
                                        <th>楼层</th>
                                        <th>uid</th>
                                        <th width="50%">内容</th>
                                        <th>点赞数</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>

                                    <tbody>
                                    <!--{loop $list['comments'] $value}-->
                                    <tr>
                                        <td>{$value['position']}</td>
                                        <td>{$value['uid']}</td>
                                        <td>{$value['content']}</td>
                                        <td>{$value['favorites']}</td>
                                        <td>
                                            <input type="hidden" value="{$value['cid']}" class="cidVal">
                                            <a href="javascript:;"  class="on-default myDelPos btn btn-default btn-sm" data-cid="{$value['cid']}" data-pos="{$value['position']}" data-uid="{$value['uid']}"><i class="fa fa-trash-o"></i></a>
                                            <!--修改点赞值-->
                                            <a href="javascript:;"  class="on-default myEdit btn btn-default btn-sm" data-cid="{$value['cid']}" data-pos="{$value['position']}" data-uid="{$value['uid']}"><i class="fa fa-pencil"></i></a>
                                        </td>
                                    </tr>
                                    <!--{/loop}-->
                                    </tbody>
                                </table>
                                <!--{if $pageUrl}-->
                                <ul class="pager">
                                    <li>
                                        <a href="{$pageUrl['prev']}"> <i class="fa fa-angle-double-left"></i>上一页</a>
                                    </li>
                                    <li>
                                        <a href="{$pageUrl['first']}"> <i class="fa"></i>第一页</a>
                                    </li>
                                    <li>
                                        <a href="{$pageUrl['next']}">下一页 <i class="fa fa-angle-double-right"></i> </a>
                                    </li>
                                </ul>
                                <!--{/if}-->
                            </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- Page Content Ends -->
    <!-- ================== -->

    <div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">

    </div><!-- /.modal -->


    <!-- Footer Start -->
    <!--{template admin_v2/footer}-->
    <!-- Footer Ends -->

</section>
<script type="text/template" id="addModal">
    <form>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="25%">类别</th>
                    <th width="75%">内容</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>评论内容</td>
                    <td >
                        <div class="form-inline">
                            <div class="form-group">
                                <textarea class="form-control" rows="3" id="content" style="width: 450px"></textarea>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>操作</td>
                    <td style="text-align: center">
                        <button type="button" class="btn btn-info addModalPost" data-bodyid="{$list['anonymousInfo']['bodyId']}">确定</button>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
</script>

<script type="text/template" id="editModal">
    {{#.}}
    <form>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="25%">类别</th>
                    <th width="75%">内容</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>点赞数</td>
                    <td>
                        <input type="text" id="praise" class="form-control"  placeholder="" value="" style="width: 170px">
                    </td>
                </tr>
                <tr>
                    <td>操作</td>
                    <td style="text-align: center">
                        <button type="button" class="btn btn-info myEditPost" data-pos="{{{position}}}" data-bodyid="{{{cid}}}" data-uid="{{{uid}}}">完成</button>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
    {{/.}}
</script>
<!-- Main Content Ends -->


<!-- js placed at the end of the document so the pages load faster -->
<script src="<!--{eval echo register_static('js/jquery.js');}-->"></script>
<script src="<!--{eval echo register_static('js/bootstrap.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/pace.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/wow.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/jquery.nicescroll.js');}-->" type="text/javascript"></script>

<script src="<!--{eval echo register_static('js/jquery.app.js');}-->"></script>
<!---->
<script src="<!--{eval echo register_static('js/handlebars-v4.0.5.js');}-->"></script>
<script src="<!--{eval echo register_static('js/handlebars-helper.js');}-->"></script>
<script src="<!--{eval echo register_static('layer/layer.js');}-->"></script>
<script src="<!--{eval echo register_static('laypage/laypage.js');}-->"></script>
<script src="<!--{eval echo register_static('laydate/laydate.js');}-->"></script>

<script src="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/datatables/dataTables.bootstrap.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.init.js');}-->"></script>


<!-- Modal-Effect -->
<script src="<!--{eval echo register_static('assets/modal-effect/js/classie.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/modal-effect/js/modalEffects.js');}-->"></script>

<script type="text/javascript">
    $(document).ready(function() {
        var tp_addModal = Handlebars.compile($('#addModal').html());
        var tp_editModal = Handlebars.compile($('#editModal').html());

        //添加评论
        $('.myAdd').click(function () {
            var html = tp_addModal();
            layer.open({
                type: 1,
                title: '添加评论',
                closeBtn: 1,
                area:['30%', '40%'],
                shadeClose: true,
                content: html
            });
        });
        $(document).off('click', '.addModalPost').on('click', '.addModalPost', function () {
            var content = $('#content').val();
            var bodyid = $(this).data('bodyid');
            $.post(
                '/admin.php?ac=commentary&op=addComment',
                {bodyId:bodyid,content:content},
                function (r) {
                    if(r == '1')
                    {
                        alert('添加成功');
                        refresh();
                    }else{
                        alert('添加失败');
                    }
                    layer.closeAll();
                }
            );
        });

        //修改点赞值
        $(document).off('click', '.myEdit').on('click', '.myEdit', function () {
            var cid = $(this).data('cid');
            var pos = $(this).data('pos');
            var uid = $(this).data('uid');
            $.post(
                '/admin.php?ac=anonymous&op=editDetail',
                {cid:cid, pos:pos, uid:uid},
                function (r) {
                    if(r._code == 1){
                        var html = tp_editModal(r.result);
                        layer.open({
                            type: 1,
                            title: '修改'+pos+'楼赞值',
                            closeBtn: 1,
                            area:['320px', '250px'],
                            shadeClose: true,
                            content: html
                        });
                    }else{
                        layer.msg(r._msg, {icon: 0});
                    }
                }
            );

        });
        $(document).off('click', '.myEditPost').on('click', '.myEditPost', function () {
            var bodyid = $(this).data('bodyid');
            var pos = $(this).data('pos');
            var uid = $(this).data('uid');
            var praise = $('#praise').val();
            var index = layer.load();
            $.post(
                '/admin.php?ac=commentary&op=editLike',
                {bodyId:bodyid, pos:pos, uid:uid, praise:praise},
                function (r) {
                    layer.close(index);
                    if (r == 1){
                        alert('修改成功');
                        refresh();
                    }else{
                        alert('修改失败');
                        refresh();
                    }
                }
            );
        });

        //删除评论
        $(document).off('click', '.myDelPos').on('click', '.myDelPos', function () {
            var bodyid = $(this).data('cid');
            var pos = $(this).data('pos');
            var uid = $(this).data('uid');
            var _this =　$(this);
            var index = layer.load();
            $.post(
                '/admin.php?ac=anonymous&op=disdel',
                {bodyId:bodyid, pos:pos, uid:uid},
                function (r) {
                    layer.close(index);
                    if (r._code == 1){
                        _this.parents('tr').remove();
                    }else{
                        layer.msg('删除失败', {icon: 0});
                    }
                }
            );
        });

        // 刷新当前页面
        function refresh(){
            setInterval(window.location.reload(),5000);
        }
    } );
</script>
</body>
</html>
